package acm.剑指offer;

import org.junit.Test;

public class 二维数组中的查找 {
    @Test
    public void test() {
//        int[][] plants = {{1,3,5}, {2, 5, 7}};
        int[][] plants = {{-1,3}};
        System.out.println(findTargetIn2DPlants(plants, 3));
    }

    public boolean findTargetIn2DPlants(int[][] plants, int target) {
        if (plants == null || plants.length == 0) return false;
        int row = 0, clo = plants[0].length - 1;
        while (row < plants.length && clo >= 0) {
            if (plants[row].length<=0){
                row++;
                continue;
            }
            if (plants[row][clo] == target) return true;
            if (plants[row][clo] < target) {
                row++;
            } else {
                clo--;
            }
        }
        return false;
    }
}
